{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 2022-11-12/week11"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.元组（tuple)  \n",
    "> 1.元组的概念和基本形态  \n",
    "> 2.元组的方法  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(18000001, 18000002, 18000003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 18000001,18000002,18000003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[18000001, 18000002, 18000003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_info_list = [18000001,18000002,18000003]\n",
    "print(user_info_list,type(user_info_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18000001\n",
      "(18000001, 18000002)\n"
     ]
    }
   ],
   "source": [
    "# 取值\n",
    "print(user_info[0])\n",
    "# 切片\n",
    "print(user_info[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=6, tm_hour=14, tm_min=40, tm_sec=22, tm_wday=6, tm_yday=310, tm_isdst=0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667716845.8527"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time() # 时间戳，可以记录互联网当中所有 数据信息产生、销毁、创建一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "user_info.count(180000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "user_info.index(180000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.集合  \n",
    "> 1.集合的概念和性质  \n",
    ">> 1.集合的唯一性  \n",
    ">> 2.集合无序性  \n",
    "\n",
    "> 2.集合的方法  \n",
    ">> 1.交集： 逻辑运算符： setA & setB , setA.intersection(B) =》 应用：推荐系统  \n",
    ">> 2.并集： 逻辑运算符： setA | setB ，setA.union(B) =》 应用：快速统计两个集合元素的个数  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'banana', 'apple', 'pear', 'orange'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {1800002,1800003,1800111,1800122}\n",
    "合唱团_user_id = {1800003,1800009,1800007,1800111,1801111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)\n",
    "{1800003, 1800111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) + len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id | 合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003, 1800007, 1800009, 1800111, 1800122, 1801111}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：如果是列表的话，想要找出重复的项？ 集合的价值\n",
    "舞蹈社_user_id_list =[1800002,1800003,1800111,1800122]\n",
    "合唱团_user_id_list = [1800003,1800009,1800007,1800111,1801111]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.字典（dict)  \n",
    "> 1.字典的概念和性质  \n",
    ">> 1.性质：  \n",
    ">>> 1.无序性  \n",
    ">>> 2.key 是唯一的(没有重复)  \n",
    ">>> 3.key 是不可变的  \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 2.字典的创建  \n",
    ">> 1.按照字典的形态创建字典  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    1800001:\"李华\",\n",
    "    1800002:\"小明\",\n",
    "    1800003:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">> 2.使用dict()方法创建字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = dict(\n",
    "    stu190001=\"小红\",\n",
    "    stu190002=\"小莉\",\n",
    "    stu190003=\"小张\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">> 3.字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "wechat = {\n",
    "    \"fgyqeu7489fhdjk\":[\"Zhichao\",\"冰岛\",\"朋友圈\",\"男\",\"159\",\"置顶聊天\",\"会话\"],\n",
    "    \"bfdjiwg84239fgd\":[\"Jack\",\"香港\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Zhichao', '冰岛', '朋友圈', '男', '159', '置顶聊天', '会话']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"fgyqeu7489fhdjk\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    1800001:\"李华\",\n",
    "    1800002:\"小明\",\n",
    "    1800003:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '李华', 1800002: '小明', 1800003: 'Jack', 1800004: 'Marry'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班[1800002]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = dict(\n",
    "    stu190001=\"小红\",\n",
    "    stu190002=\"小莉\",\n",
    "    stu190003=\"小张\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu190001': '小红', 'stu190002': '小莉', 'stu190003': '小张'}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小莉'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班[\"stu190002\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 课后预习字典的方法  \n",
    "* 取出一个列表的第10个数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
